package server.dbconnector;

import java.sql.*;

public class DatabaseConnector {
	private Connection con;
	public DatabaseConnector()throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost:3309/workassistant";
		con = DriverManager.getConnection(url, "root", "1qaz2wsx");
		System.out.println("URL: " + url);
		System.out.println("Connection: " + con);
	}
	public void disconnect()throws SQLException{
		con.close();
	}
	public void commit(String statement) throws SQLException{
		Statement sta=con.createStatement();
		sta.executeUpdate(statement);
		sta.close();
	}
	public ResultSet query(String statement) throws SQLException{
		Statement sta=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		sta.executeQuery(statement);
		ResultSet rs=sta.getResultSet();
		return rs;
	}
}
